﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq;
/// <summary>
/// Summary description for LinqHelper
/// </summary>

namespace System.Linq
{
    public static class LinqHelper
    {
        public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> callback)
        {
            if (enumerable == null)
            {
                throw new ArgumentNullException("enumerable");
            }

            ForEachHelper(enumerable, (x, i) => callback(x));
        }

        public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T, int> callback)
        {
            if (enumerable == null)
            {
                throw new ArgumentNullException("enumerable");
            }

            ForEachHelper(enumerable, callback);
        }

        private static void ForEachHelper<T>(this IEnumerable<T> enumerable, Action<T, int> callback)
        {
            int count = 0;
            foreach (var cur in enumerable)
            {
                callback(cur, count);
                count++;
            }
        }
    }
}
